package leetcode.tree_problem;

/**
 * 110. 平衡二叉树
 * https://leetcode-cn.com/problems/balanced-binary-tree/
 */
public class IsBalanced {
    public boolean isBalanced(TreeNode root) {
        if (root == null)
            return true;
        if (Math.abs(height(root.left) - height(root.right)) > 1){
            return false;
        }
        return isBalanced(root.left) && isBalanced(root.right);

    }
    public int height(TreeNode root){
        if (root == null)
            return 0;
        return 1 + Math.max(height(root.left) , height(root.right));
    }
}
